<?php

namespace addons\test\app\api\controller;


use app\common\controller\BaseApiController;
use app\common\model\User;
use fast\Random;

class Index extends BaseApiController
{
    protected $noNeedLogin = ['login'];
    protected $noNeedRight = ['*'];
    public function login()
    {
        $data = $this->param();
        $has = User::where('mobile', $data['mobile'])->find();
        if(empty($has)){
            //$username, $password, $email = '', $mobile = '', $extend = []
            $res = $this->auth->register($data['mobile'],Random::alnum(),$data['mobile'].'@qq.com',$data['mobile'],['pid'=>$data['pid']??""]);
        }else{
            $res = $this->auth->direct($has['id']);
        }
        return $this->success('登录成功',['user_info'=>$this->auth->getUser(),'token'=>$this->auth->getToken()]);
    }
    public function index()
    {
        echo "<pre>";
        print_r($this->auth->id);
        exit;
    }
}